package com.bjmashibing.system;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bjmashibing.system.huawei.domain.History;
import com.bjmashibing.system.huawei.jdbc.SpringJdbcTemplate;
import com.bjmashibing.system.huawei.static_var;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Classname test4
 * @Description TODO
 * @Date 2020/10/10/010 11:17
 * @Created by Administrator
 */
public class test4 {
    private final static Logger logger = LoggerFactory.getLogger(test4.class);
    @Test
    public void test() {
        /*SocketChannel socketChannel = null;
        static_var.map_socket.put("192.168.2.203:12345",socketChannel);
        static_var.map_socket.put("192.168.2.203:22345",socketChannel);
        logger.info("" +static_var.map_socket);*/


//        Messaging.send_message_fcm_to_regid();
        SpringJdbcTemplate springJdbcTemplate = new SpringJdbcTemplate();
        int receipt = 0;
        springJdbcTemplate.token_insert_according_to_machine_id("111111","English","OPPO","868626044227521",64,receipt);

        springJdbcTemplate.token_delete("111111");
    }
    @Test
    public void test0() {
        /*SocketChannel socketChannel = null;
        static_var.map_socket.put("192.168.2.203:12345",socketChannel);
        static_var.map_socket.put("192.168.2.203:22345",socketChannel);
        logger.info("" +static_var.map_socket);*/


//        Messaging.send_message_fcm_to_regid();
        SpringJdbcTemplate springJdbcTemplate = new SpringJdbcTemplate();
        int receipt = 0;
//        springJdbcTemplate.token_insert_according_to_machine_id("111111","English","OPPO","868626044227521",64,receipt);

        springJdbcTemplate.token_delete("111111");
    }
    @Test
    public void test2() {

        String str_machine_name = "861111111111111";
        String str_alarm_event = "#000007|1400 00 189";
        String str_time = "2020-11-28 12:00:33";
        String str_machine_name2 = "863333333333333";
        String str_alarm_event2 = "#000007|3400 00 189";
        String str_time2 = "2020-11-28 12:00:34";

        static_var.insert_alarm_event_into_map_history(str_machine_name,str_alarm_event,str_time);
        static_var.insert_alarm_event_into_map_history(str_machine_name,str_alarm_event2,str_time2);
        static_var.insert_alarm_event_into_map_history(str_machine_name2,str_alarm_event,str_time);
        static_var.insert_alarm_event_into_map_history(str_machine_name2,str_alarm_event2,str_time2);

        logger.info("static_var.map_history=" +static_var.map_history);


        String str_alarm_events = "";

        boolean bflag = static_var.map_history.containsKey(str_machine_name);
        if (bflag) {

            List<History> list_history = static_var.map_history.get(str_machine_name);
            logger.info("test2,list_history=" + list_history);
            logger.info("test2,list_history=" + list_history.size());

            boolean b_has_token = false;
            for (int i = 0; i < list_history.size(); i++) {
                String str_history_alarm_event_temp = list_history.get(i).getHistory_alarm_event();
                String str_history_create_time = list_history.get(i).getHistory_create_time();

                logger.info("str_history_alarm_event_temp=" + str_history_alarm_event_temp);
                logger.info("str_history_create_time=" + str_history_create_time);
                str_alarm_events = str_alarm_events + str_history_alarm_event_temp + str_history_create_time;
            }

            logger.info("str_alarm_events=" + str_alarm_events);
        }

    }

    public void plus(int a[]) {
        a[0] = 2 + 3;

    }

    @Test
    public void test3(){

        int a[] = new int[1];
        plus(a);
        logger.info("a[0]"+ a[0]);
    }

    @Test
    public void test4() {
        String str_machine_name = "861111111111111";
        String str_alarm_event = "#000007|1400 00 189";
        String str_time = "2020-11-28 12:00:33";
        String str_machine_name2 = "863333333333333";
        String str_alarm_event2 = "#000007|3400 00 189";
        String str_time2 = "2020-11-28 12:00:34";

//        static_var.insert_alarm_event_into_map_history(str_machine_name,str_alarm_event,str_time);
//        static_var.insert_alarm_event_into_map_history(str_machine_name,str_alarm_event2,str_time2);
//        static_var.insert_alarm_event_into_map_history(str_machine_name2,str_alarm_event,str_time);
//        static_var.insert_alarm_event_into_map_history(str_machine_name2,str_alarm_event2,str_time2);
        String str_alarm_events[] = new String[1];
        Integer nums [] = new Integer[1];
        static_var.get_alarm_event_from_map_history(str_machine_name,str_alarm_events,nums);
        logger.info(str_alarm_events[0]);
        logger.info("" + nums[0]);
    }

    @Test
    public void test_json() {
        String json = "{  \"error\": {    \"code\": 404,    \"message\": \"Requested entity was not found.\",    \"status\": \"NOT_FOUND\",    \"details\": [      {        \"@type\": \"type.googleapis.com/google.firebase.fcm.v1.FcmError\",        \"errorCode\": \"UNREGISTERED\"      }    ]  }}";
        JSONObject jsonObject = JSONObject.parseObject(json);
        logger.info("jsonObject=" + jsonObject);
        JSONObject error = jsonObject.getJSONObject("error");

        JSONArray details = error.getJSONArray("details");
        for (int i = 0; i < details.size(); i++) {
        JSONObject obj = (JSONObject) details.get(i);
        Map<String, Object> map_fcm = new HashMap<String, Object>();
        map_fcm = JSONObject.parseObject(obj.toJSONString(), Map.class);
        logger.info("@type=" + map_fcm.get("@type"));
        logger.info("errorCode=" + map_fcm.get("errorCode"));
      }
    }
}
